package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.entity.Role;
import cn.gjculture.shopping.api.service.RoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/role")
public class RoleController {
    
    @Autowired
    RoleService roleService;

    @ApiOperation(value = "新增", notes = "新增角色")
    @ApiImplicitParam(name = "Role", value = "角色对象", required = true, dataType = "Object")
    @PostMapping
    public Return save(Role role) {
        Return ret = new Return();
        if(roleService.insert(role)>0){
            ret.getCommon().setRet(true);
        }
        return ret;

    }
    @ApiOperation(value = "修改角色", notes = "修改角色")
    @ApiImplicitParam(name = "Role", value = "角色对象", required = true, dataType = "Object")
    @PutMapping
    public Return<Role> update(Role role){
        Return<Role> ret=new Return<>();
        if(roleService.update(role)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "获取角色列表", notes = "获取角色列表")
    @GetMapping
    public Return<List<Role>> query(PageInfo pageInfo) {
        Return<List<Role>> ret = new Return<>();
        List<Role> roles = roleService.query();
        ret.setData(roles);
        return ret;
    }

    @ApiOperation(value = "获取角色", notes = "获取角色")
    @ApiImplicitParam(name = "roleId", value = "角色ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{roleId}")
    public Return<Role> gitActivity(@PathVariable(value = "roleId") String roleId) {
        Return<Role> ret = new Return<>();
        Role Role = roleService.queryById(roleId);
        ret.setData(Role);
        return ret;
    }


    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParam(name = "roleIds", value = "角色ID", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{roleIds}")
    public Return<Role> delete(@PathVariable(value = "roleIds") List<String> roleIds) {
        Return<Role> ret = new Return<>();
        if(roleService.delete(roleIds)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }
}
